package com.filldream.fastboot.common.entity.db;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.filldream.fastboot.common.okutil.cls.dto.ClsNewsSimpleItem;
import com.filldream.fastboot.common.util.JsonUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * 东财公告
 */
@Data
@Accessors(chain = true)
public class CfAnn {

    @TableId(value = "art_code", type = IdType.NONE)
    private String artCode;

    private String title;

    private String stockCode;

    private Date sortDate;

    @ApiModelProperty(value = "机器人接收者")
    private String sendOwner;

    @TableField(exist = false)
    private List<CfAnnCode> codes;

    @Data
    @Accessors(chain = true)
    public static class CfAnnCode {
        private String stockCode;
        private String shortName;
    }

    public List<String> getSendOwnerList() {
        if(StringUtils.isBlank(sendOwner)){
            return new LinkedList<>();
        }
        return JsonUtil.fromJosnArray(  sendOwner, String.class);
    }

    public ClsNewsSimpleItem toClsNewsSimpleItem(){
        ClsNewsSimpleItem item = new ClsNewsSimpleItem();
        item.setTitle( title );
        item.setIsTop(true);
        item.setLinkUrl("https://data.eastmoney.com/notices/detail/"+stockCode+"/"+artCode+".html");
        return item;
    }

}
